<template>
  <div>
    <el-table :data="tableData" stripe style="width: 100%" max-height="600">
      <el-table-column prop="content" label="意见描述" show-overflow-tooltip>
        <template slot-scope="scope">
          <p class="sheng"> {{ scope.row.content | htmlFormat }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="createBy" label="创建人" width="140">
        <template slot-scope="scope"
          >{{ scope.row.sysUser.userName || '--' }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="180">
      </el-table-column>
      <el-table-column label="操作" width="220">
        <template slot-scope="{ row }">
          <el-button-group>
            <el-button type="primary" size="mini" @click="handleView(row)"
              >查看
            </el-button>
            <el-button
              type="success"
              size="mini"
              @click="handleMessage(row)"
              :disabled="row.createBy == $store.getters.userId"
              >私信</el-button
            >
            <el-button type="danger" size="mini" @click="handleDelete(row)"
              >删除</el-button
            >
          </el-button-group>
        </template>
      </el-table-column>
      <div slot="empty" class="emptyBg">
        <el-empty :image-size="200"></el-empty>
      </div>
    </el-table>
    <Pagination
      v-show="parseInt(pageObj.count) > 0"
      :total="parseInt(pageObj.count)"
      @change="getList"
      :page.sync="listQuery.page"
      :limit.sync="listQuery.limit"
    />
    <SendMessage />
  </div>
</template>
<script>
import { tbSysFeedQuery, tbSysFeedDelete } from '@/api/admin/system/feedback.js'
import Bus from '@/utils/bus.js'
export default {
  components: {
    SendMessage: () => import('@/components/sendMessage'),
  },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10,
      },
      tableData: [],
      pageObj: {},
    }
  },
  mounted() {
    this.getList()
    Bus.$on('refreshFeedbackList', (v) => {
      if (v) {
        Object.assign(this.listQuery, v)
      }
      this.getList()
    })
  },
  beforeDestroy() {
    Bus.$off('refreshFeedbackList')
  },
  methods: {
    getList() {
      tbSysFeedQuery(this.listQuery).then((res) => {
        this.tableData = res.data.data
        this.pageObj = res.data
      })
    },
    //查看详情
    handleView(row) {
      Bus.$emit('showDialogFeedbackDetail', row)
    },
    // 发送私信
    handleMessage(row) {
      Bus.$emit('sendMessage', [row.createBy])
    },
    //删除确认
    handleDelete(row) {
      this.$confirm('确定要删除吗?', '提示', {
        confirmButtonText: '删除',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.delete(row)
        })
        .catch(() => {})
    },
    //删除
    delete(row) {
      tbSysFeedDelete(row.id).then((res) => {
        this.getList()
        this.$message({
          message: '操作成功',
          type: 'success',
        })
      })
    },
  },
}
</script>